package c.c.b.b.f;

import android.os.Handler;
import android.os.SystemClock;
import c.c.b.b.e.c;
import c.c.b.b.e.f;
import c.c.b.b.i.d;
import java.net.URL;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

/* compiled from: ExecutorDelivery */
public class k implements d {
    public final Executor a;
    public final Executor b = Executors.newCachedThreadPool();
    public c c = f.a();

    /* compiled from: ExecutorDelivery */
    public class a implements Executor {
        public final /* synthetic */ Handler a;

        public a(k kVar, Handler handler) {
            this.a = handler;
        }

        public void execute(Runnable runnable) {
            this.a.post(runnable);
        }
    }

    /* compiled from: ExecutorDelivery */
    public static class b implements Runnable {
        public final c a;
        public final p b;
        public final Runnable c;

        public b(c cVar, p pVar, Runnable runnable) {
            this.a = cVar;
            this.b = pVar;
            this.c = runnable;
        }

        public void run() {
            if (this.a.isCanceled()) {
                this.a.a("canceled-at-delivery");
                return;
            }
            this.b.g = this.a.getExtra();
            this.b.e = SystemClock.elapsedRealtime() - this.a.getStartTime();
            this.b.f = this.a.getNetDuration();
            if (this.b.a()) {
                try {
                    this.a.a(this.b);
                } catch (Throwable unused) {
                }
            } else {
                this.a.deliverError(this.b);
            }
            if (this.b.d) {
                this.a.addMarker("intermediate-response");
            } else {
                this.a.a("done");
            }
            Runnable runnable = this.c;
            if (runnable != null) {
                try {
                    runnable.run();
                } catch (Throwable unused2) {
                }
            }
        }
    }

    public k(Handler handler) {
        this.a = new a(this, handler);
    }

    public void a(c<?> cVar, p<?> pVar, Runnable runnable) {
        cVar.markDelivered();
        cVar.addMarker("post-response");
        (cVar.isResponseOnMain() ? this.a : this.b).execute(new b(cVar, pVar, runnable));
        c cVar2 = this.c;
        if (cVar2 != null) {
            ((f) cVar2).c(cVar, pVar);
        }
    }

    public void b(c<?> cVar, c.c.b.b.h.a aVar) {
        cVar.addMarker("post-error");
        URL url = null;
        (cVar.isResponseOnMain() ? this.a : this.b).execute(new b(cVar, new p(aVar), null));
        c cVar2 = this.c;
        if (cVar2 != null) {
            f fVar = (f) cVar2;
            synchronized (fVar) {
                if (aVar == null) {
                } else if (!fVar.m) {
                } else if (b.i.b.f.w(fVar.c)) {
                    try {
                        url = new URL(cVar.getUrl());
                    } catch (Exception unused) {
                    }
                    if (url == null) {
                        return;
                    }
                    String protocol = url.getProtocol();
                    String host = url.getHost();
                    String path = url.getPath();
                    String ipAddrStr = cVar.getIpAddrStr();
                    if ("http".equals(protocol) || "https".equals(protocol)) {
                        c.c.b.b.e.d g = fVar.g();
                        if (g == null) {
                            return;
                        }
                        StringBuilder stringBuilder = new StringBuilder();
                        stringBuilder.append("onError, url matched: ");
                        stringBuilder.append(protocol);
                        stringBuilder.append("://");
                        stringBuilder.append(host);
                        stringBuilder.append("#");
                        stringBuilder.append(ipAddrStr);
                        stringBuilder.append("# ");
                        stringBuilder.append(fVar.g);
                        stringBuilder.append("#");
                        stringBuilder.append(fVar.h.size());
                        stringBuilder.append("#");
                        stringBuilder.append(fVar.i.size());
                        stringBuilder.append(" ");
                        stringBuilder.append(fVar.j);
                        stringBuilder.append("#");
                        stringBuilder.append(fVar.k.size());
                        stringBuilder.append("#");
                        stringBuilder.append(fVar.l.size());
                        c.c.b.b.g.b.a("TNCManager", stringBuilder.toString());
                        fVar.g++;
                        fVar.h.put(path, Integer.valueOf(0));
                        fVar.i.put(ipAddrStr, Integer.valueOf(0));
                        if (fVar.g >= g.e && fVar.h.size() >= g.f && fVar.i.size() >= g.g) {
                            StringBuilder stringBuilder2 = new StringBuilder();
                            stringBuilder2.append("onError, url doUpate: ");
                            stringBuilder2.append(protocol);
                            stringBuilder2.append("://");
                            stringBuilder2.append(host);
                            stringBuilder2.append("#");
                            stringBuilder2.append(ipAddrStr);
                            c.c.b.b.g.b.a("TNCManager", stringBuilder2.toString());
                            fVar.e(false, 0);
                            fVar.i();
                        }
                        fVar.f(host);
                        return;
                    }
                }
            }
        }
    }
}
